// 1.引入公用样式表
require("../../assets/css/index.less");
// require("../../assets/fonts/iconfont.css")

// 2.引入当前样式表
require("./echartsData.less");

// 引入插件
import * as echarts from 'echarts';
// 3.引入公用js模块
let validator = require("../../utils/validator.js");
let https = require("../../utils/https.js");

// 4.引入工具函数
let dom = require("../../utils/dom.js");
dom.ready(function () {
    dom.goTo("#goHome", "home");
    // let option
    // let xData
    // let yData
    // 获取当前用户数据
    https.get("/api/exercise", function (res) {
        console.log("res", res);
        if (res.errno == 0) {
            // console.log(res.data.days);
            let xData = res.data.days.map(v => {
                // console.log(v);
                // console.log(v.date);
                console.log(v.date.slice(5));
                return v.date.slice(5)
            })
            let yData = res.data.days.map(v => {
                return v.sumDuration
            })
            console.log(xData, yData);
            let options = {
                title: {
                    text: '近7天运动时长'
                },
                //网格相关
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                tooltip: {},
                xAxis: {
                    data: xData,
                    axisLabel: {
                        rotate: 45
                    },
                    axisTick: {
                        alignWithLabel: true
                    }
                },
                yAxis: {},
                series: [{
                    type: 'bar',
                    data: yData
                }]
            }
            renderChart("#duration", options)
            renderChart("#sort", options)
            // renderChart("#sportsData", options)
        }
    })

    // 封装一个渲染函数
    function renderChart(obj, options) {
        let myChart = echarts.init(dom.$(obj))
        myChart.setOption(options)
    }





});
